// Copyright (c) Symbian Ltd 2008. All rights reserved.
#include <e32math.h>
#include "roshambo.h"

TRoshambo::TRoshambo()
: iLocalPlayer(ENone), iOpponent(ENone){}

void TRoshambo::SinglePlayerGame(TElement aLocalPlayer)
	{
	iLocalPlayer = aLocalPlayer;
	TUint32 randomChoice = (Math::Random())%3;
	ASSERT( (randomChoice>=0) && (randomChoice<=3) ); 
	iOpponent = (TElement)randomChoice;
	}

//enum TElement {ENone = -1, ERock = 0, EPaper = 1, EScissors = 2};	
TRoshambo::TResult TRoshambo::CalculateResult() const
	{
	TResult result = ENoContest;
	
	if (iLocalPlayer==ENone)
		{
		if (iOpponent==ENone)
			result = ENoContest; // No contest if neither player selected
		else
			result = ELose;	  // Opponent won by default 
		}
		
	else if (iOpponent>iLocalPlayer)
		{
		if ( (iOpponent==EScissors) && (iLocalPlayer==ERock) ) // Player wins
			result = EWin;
		else // Opponent wins
			result = ELose;
		}
		
	else if (iLocalPlayer > iOpponent)
		{
		if ( (iLocalPlayer==EScissors) && (iOpponent==ERock) ) // Opponent wins
			result = ELose;
		else // Player wins
			result = EWin;
		}
		
	else if (iLocalPlayer==iOpponent)
		result = EDraw;
	
	else
		ASSERT(EFalse);; // Shouldn't get here		
		
	return (result);		
	}
